unit MotGrafWin;
{
    Copyright 2008, travieorama@googlemail.com

    This file is part of the taviesadora project

    taviesadora is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    taviesadora is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.


}
interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls,vibdriver,Types;

const
{		ANALOG CHANNELS       }
	CHANNEL_SWITCH1	=0;
	CHANNEL_SWITCH2	=11;
	CHANNEL_POTI1	=3;
	CHANNEL_POTI2	=4;
	CHANNEL_CURR1	=12;
	CHANNEL_CURR2	=15;
	CHANNEL_CURR3	=13;
	CHANNEL_CURR4	=1;
	CHANNEL_VOLT1	=8;
	CHANNEL_VOLT2	=14;
	CHANNEL_VOLT3	=10;
	CHANNEL_VOLT4	=9;
	CHANNEL_ANIN1	=2;
	CHANNEL_ANIN2	=5;
	CHANNEL_ANIN3	=6;
	CHANNEL_SUPPLY	=7;
  
type
  TRecordings=record
    y:integer;
    x:integer;
    color:TColor;
  end;
  TFrmAnaWin = class(TForm)
    btnClose: TButton;
    pbGraph: TImage;
    btnclear: TButton;
    constructor create(Owner:TComponent;VibDrver:TVibHardwareDriver);
    procedure NewAnaValue(Value,Channel:integer);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure btnCloseClick(Sender: TObject);
    procedure btnclearClick(Sender: TObject);
  private
    VibDrver:TVibHardwareDriver;
    RecPostitions: array[0..15] of TRecordings;
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  FrmAnaWin: TFrmAnaWin;

implementation

{$R *.dfm}

{ TForm2 }

constructor TFrmAnaWin.create(Owner:TComponent;VibDrver:TVibHardwareDriver);
var
  i:integer;
begin
  inherited create(Owner);
  for i := 0 to high(RecPostitions) do begin
    RecPostitions[i].X := 0;
  end;
  RecPostitions[0].color := clblack;
  RecPostitions[1].color := clMaroon;
  RecPostitions[2].color := clGreen;
  RecPostitions[3].color := clOlive;
  RecPostitions[4].color := clNavy;
  RecPostitions[5].color := clPurple;
  RecPostitions[6].color := clTeal;
  RecPostitions[7].color := clRed;
  RecPostitions[8].color := clLime;
  RecPostitions[9].color := clYellow;
  RecPostitions[10].color := clBlue;
  RecPostitions[11].color := clFuchsia;
  RecPostitions[12].color := clAqua;
  RecPostitions[13].color := clMoneyGreen;
  RecPostitions[14].color := clSkyBlue;
  RecPostitions[15].color := clCream;
  self.VibDrver := VibDrver;
  DoubleBuffered := true;
  show;
  VibDrver.SetChannelRecordingWin(self);
  VibDrver.StartAnaChannelRecording(CHANNEL_POTI2);
  VibDrver.StartAnaChannelRecording(CHANNEL_POTI2);
end;

procedure TFrmAnaWin.NewAnaValue(Value,Channel:integer);
var
  y:integer;
begin
  with pbGraph.Canvas do begin
    pen.Color := RecPostitions[Channel].color;
    MoveTo(RecPostitions[Channel].X,RecPostitions[Channel].y);
    y := pbGraph.Height-(Value div 2)-10;
    LineTo(RecPostitions[Channel].X+1,y);
  end;
  RecPostitions[Channel].y := y;
  RecPostitions[Channel].X := RecPostitions[Channel].X+1;
  if RecPostitions[Channel].X+1 >= pbGraph.Width then
    RecPostitions[Channel].X := 0;
end;


procedure TFrmAnaWin.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  VibDrver.StopAnaChannelRecording(CHANNEL_CURR1);
  VibDrver.StopAnaChannelRecording(CHANNEL_VOLT1);
  VibDrver.SetChannelRecordingWin(nil);
  Action := caFree;
end;

procedure TFrmAnaWin.btnCloseClick(Sender: TObject);
begin
  close;
end;

procedure TFrmAnaWin.btnclearClick(Sender: TObject);
var
  i:integer;
begin
  for i := 0 to high(RecPostitions) do begin
    RecPostitions[i].X := 0;
  end;
  with pbGraph.Canvas do begin
    pen.Color := clWhite;
    brush.Color := clWhite;
    Rectangle(0,0,pbGraph.Width,pbGraph.Height);
  end;
end;

end.
